<template>
    <div class="bind-camera">
        <search-table
            :columns="columns"
            :data="targetResetRecords"
            :total="total"
            :page.sync="pageIndex"
            :size.sync="pageSize"
            @queryFun="getTargetResetRecords">
            <template slot="select-group">
                <Select filterable
                    v-model="teamId"
                    placeholder="请选择团队"
                    filterable
                    clearable
                    @on-change="getTargetResetRecords(1)">
                    <Option  v-for="item in teamList" :value="item.id"  :key="item.id" :title="item.name">{{item.name}}</Option>
                </Select>
                <Select filterable 
                    v-model="targetName"
                    @on-change="getTargetResetRecords(1)" 
                    clearable
                    filterable
                    placeholder="请选择题目">
                    <Option v-for="item in questionList" :value="item.name" :key="item.id" :title="item.name">{{ item.name }}</Option>
                </Select>
                <Select filterable 
                    v-model="type"
                    @on-change="getTargetResetRecords(1)" 
                    clearable
                    filterable
                    placeholder="请选择机器类型">
                    <Option :value="0">防守机</Option>
                    <Option :value="1">攻击机</Option>
                </Select>
            </template>
        </search-table>
    </div>
</template>

<script>
    import SearchTable from '@/components/SearchTable/SearchTable'
    import { getTargetResetRecords, getTargetTeamList_new } from '@/api/drill_compete'
    import teamMixin from '@/mixin/groupMixin'

    export default {
        name: 'ResetTargetStatic',
        components: {
            SearchTable
        },
        mixins: [
            teamMixin,
        ],
        props: {
        },
        data() {
            return {
                questionList: [],
                type: '',
                targetName: '', // 搜索条件，靶标名称
                teamId: '', // 搜索条件，团队ID
                total: 0, // 总数据量
                pageSize: 10, // 分页大小
                pageIndex: 1, // 当前页
                columns: [
                    {
                        placement: 'top-left',
                        title: '团队名称',
                        key: 'teamName',
                        align: 'center',
                        tooltip: true,
                        width: 230
                    },
                    {
                        title: '题目名称',
                        key: 'targetName',
                        align: 'center',
                        tooltip: true,
                        width: 230
                    },
                    {
                        title: '机器类型',
                        width: 140,
                        key: 'type',
                        render:(h,params) => {
                            let type = params.row.type
                            return h('Tag', {
                                props:{
                                    color: type === 0 ? 'red' : 'blue'
                                }, 
                            }, type === 0 ? '防守机' : '攻击机')
                        }
                    },
                    {
                        title: '创建时间',
                        width: 240,
                        key: 'createTime'
                    },
                    {
                        title: '重置状态',
                        width: 140,
                        key: 'status',
                        render:(h,params) => {
                            let status = params.row.state
                            return h('Tag', {
                                props:{
                                    color: status === 0 ? 'red' : 'blue'
                                }, 
                            }, status === 0 ? '失败' : '成功')
                        }
                    },
                ],
                allTargetTeamData: [],
                targetResetRecords: [] // 分页获取已绑定的摄像头列表
            }
        },
        mounted() {
            this.$nextTick(() => {
                this.getTargetResetRecords()
                this.getQuestions()
            })
        },
        methods: {
            getQuestions() {
                getTargetTeamList_new({
                    pageIndex:1,
                    pageSize:2147483647,
                    sceneId:this.$route.query.id,
                    projectId:this.$route.query.prjid
                }).then(data => {
                    if(data.code==1){
                        this.questionList = data.data.items || data.data;
                    }
                })
            },
            // 查询机器重置记录
            getTargetResetRecords(pageNow) {
                this.pageIndex = pageNow || this.pageIndex
                getTargetResetRecords({
                    sceneId: this.$route.query.id,
                    pageIndex: this.pageIndex, 
                    pageSize: this.pageSize,
                    targetName: this.targetName,
                    teamId: this.teamId,
                    type: this.type
                }).then(({ code, data, message }) => {
                    if (code !== 1) {
                        this.$Message.warning(message)
                    } else {
                        this.total = data.total || 0
                        this.targetResetRecords = data.items || []
                    }
                }).catch(() => {
                    this.$Message.error('查询机器重置记录异常')
                })
            },
        }
    }
</script>

<style scoped>
</style>